<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(A) {
      //给数组A降序排列，最大边小于其他两边和即返回最长周长
      A.sort((a, b) => b - a);
      var res = 0;
      for (var i = 0; i < A.length - 2; i++) {
        if (A[i] < A[i + 1] + A[i + 2]) {
          return A[i] + A[i + 1] + A[i + 2];
        }
      }
      return res;
    };
    console.log(arr([2, 1, 2]));
  </script>
</body>

</html>